package kit.edu.lego.gruppe3.levels.line;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import lejos.nxt.LightSensor;
import lejos.nxt.UltrasonicSensor;
import lejos.robotics.navigation.DifferentialPilot;
import lejos.robotics.subsumption.*;
import kit.edu.lego.gruppe3.sensors.Scanner;

public class RotateBridge implements Behavior
{

	private DifferentialPilot robot = ComponentsRepository.getInstance().getRobotPilot();
	LightSensor lightSensor = ComponentsRepository.getInstance().getLightSensor();
	UltrasonicSensor sonicSensor = ComponentsRepository.getInstance().getSonicSensor();
	
	public boolean status = true;
	
	@Override
	public void action()
	{	

		robot.stop();
		if(status)
		{
			robot.travel(12);
			try {
				Thread.sleep(1500);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			robot.travel(20);
			
			LineSolver linie = new LineSolver();
			linie.start();
			
			status = false;
		}
	}

	@Override
	public void suppress()
	{

	}

	@Override
	public boolean takeControl()
	{
		return LevelSelector.getInstance().isLine()
		&& lightSensor.readValue() >= 60;
	}

}
